home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form SierpBoxForm
- Caption = "Sierpinski Box"
- ClientHeight = 4335
- ClientLeft = 2280
- ClientTop = 1185
- ClientWidth = 5400
- Height = 5025
- Left = 2220
- LinkTopic = "Form1"
- ScaleHeight = 289
- ScaleMode = 3 'Pixel
- ScaleWidth = 360
- Top = 555
- Width = 5520
- Begin VB.TextBox LevelText
- Height = 285
- Left = 600
- MaxLength = 3
- TabIndex = 0
- Text = "4"
- Top = 0
- Width = 375
- End
- Begin VB.PictureBox Canvas
- AutoRedraw = -1 'True
- FillStyle = 0 'Solid
- Height = 4335
- Left = 1080
- ScaleHeight = 285
- ScaleMode = 3 'Pixel
- ScaleWidth = 277
- TabIndex = 3
- Top = 0
- Width = 4215
- End
- Begin VB.CommandButton CmdGo
- Caption = "Go"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 480
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "Level"
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 2
- Top = 0
- Width = 495
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "SierpBoxForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim TheLevel As Integer
- Dim StartX1 As Single
- Dim StartY1 As Single
- Dim StartX4 As Single
- Dim StartY4 As Single
- ' ************************************************
- ' Draw a Sierpinski box.
- ' ************************************************
- Sub SierpBox(level As Integer, x1 As Single, y1 As Single, x4 As Single, y4 As Single)
- Dim x2 As Single
- Dim y2 As Single
- Dim x3 As Single
- Dim y3 As Single
- ' Fill the square.
- Canvas.Line (x1, y1)-(x4, y4), vbBlack, BF
-
- ' If this is a level 0 gasket, we're done.
- If level < 1 Then Exit Sub
-
- ' Find the corners of the sub-squares.
- x2 = (2 * x1 + x4) / 3
- x3 = (x1 + 2 * x4) / 3
- y2 = (2 * y1 + y4) / 3
- y3 = (y1 + 2 * y4) / 3
- ' Erase the middle square.
- Canvas.Line (x2, y2)-(x3, y3), Canvas.BackColor, BF
- ' Recursively make the other gaskets.
- SierpBox level - 1, x1, y1, x2, y2
- SierpBox level - 1, x2, y1, x3, y2
- SierpBox level - 1, x3, y1, x4, y2
- SierpBox level - 1, x1, y2, x2, y3
- SierpBox level - 1, x3, y2, x4, y3
- SierpBox level - 1, x1, y3, x2, y4
- SierpBox level - 1, x2, y3, x3, y4
- SierpBox level - 1, x3, y3, x4, y4
- End Sub
- Sub GetParameters()
- If Not IsNumeric(LevelText.Text) Then _
- LevelText.Text = "5"
- TheLevel = CInt(LevelText.Text)
- End Sub
- Private Sub CmdGo_Click()
- Dim i As Integer
- MousePointer = vbHourglass
- DoEvents
- ' Get the parameters.
- GetParameters
- ' Draw the curve.
- Canvas.Cls
- SierpBox TheLevel, StartX1, StartY1, StartX4, StartY4
- MousePointer = vbDefault
- End Sub
- Private Sub Form_Resize()
- Canvas.Move Canvas.Left, 0, _
- ScaleWidth - Canvas.Left, ScaleHeight - 1
- ' See where the first corners should be.
- StartX1 = Canvas.ScaleWidth * 0.05
- StartX4 = Canvas.ScaleWidth * 0.95
- StartY1 = Canvas.ScaleHeight * 0.05
- StartY4 = Canvas.ScaleHeight * 0.95
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-